package com.bkgy.modular.tbdecsionrule.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bkgy.modular.tbdecsionrule.dao.TbDsjHourProductionMapper;
import com.bkgy.modular.tbdecsionrule.dto.TbDsjHourProductionDto;
import com.bkgy.modular.tbdecsionrule.entity.TbDsjHourProduction;
import com.bkgy.modular.tbdecsionrule.service.TbDsjHourProductionService;
import com.bkgy.sys.common.entity.ResultData;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author
 * @version 1.0
 * @ClassName TbDsjHourProductionServiceImpl
 * @date 2023/3/28 15:52
 */
@Service
public class TbDsjHourProductionServiceImpl extends ServiceImpl<TbDsjHourProductionMapper, TbDsjHourProduction> implements TbDsjHourProductionService {
    @Resource
    private TbDsjHourProductionMapper tbDsjHourProductionMapper;

    @Override
    public ResultData findProductionData(JSONObject jsonObject) {
        LambdaQueryWrapper<TbDsjHourProduction> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TbDsjHourProduction::getLineno,1720);
        List<TbDsjHourProduction> tbDsjHourProductions = tbDsjHourProductionMapper.selectList(queryWrapper);
        return ResultData.ResultDataSuccess(tbDsjHourProductions);
    }

    @Override
    public ResultData updateProductionData(TbDsjHourProductionDto tbDsjHourProductionDto) {
        // 获取参数
        Double grade = tbDsjHourProductionDto.getGrade();
        // 创建查询构造器
        LambdaQueryWrapper<TbDsjHourProduction> queryWrapper = new LambdaQueryWrapper<>();
        // 根据分组代码进行查询数据
        queryWrapper.eq(TbDsjHourProduction::getGrade,grade);
        TbDsjHourProduction tbDsjHourProduction = tbDsjHourProductionMapper.selectOne(queryWrapper);
        if (tbDsjHourProduction == null) {
            return ResultData.ResultDataFaultSelf("数据不存在",null);
        }
        BeanUtils.copyProperties(tbDsjHourProductionDto,tbDsjHourProduction);
        tbDsjHourProductionMapper.update(tbDsjHourProduction,queryWrapper);
        return ResultData.ResultDataFaultSelf("修改成功",null);
    }
}
